<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="generator" content="MATLAB R2016a"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,IE=9,chrome=1"/>
<title>实用计算方法实验一——三次样条插值</title>
<style type="text/css">
* {margin: 0; padding: 0;}
body {text-align: start; line-height: 17.2339992523193px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Consolas, Inconsolata, Menlo, monospace; font-style: normal; font-size: 14px; font-weight: normal; text-decoration: none; white-space: normal; }
h1, h2 {font-weight: normal;}
.content { padding: 30px; }

.S0 { margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S1 { line-height: 26.3999996185303px; min-height: 24px; white-space: pre-wrap; color: rgb(213, 80, 0); font-family: Helvetica, Arial, sans-serif; font-size: 22.0000019073486px; white-space: pre-wrap; margin-left: 4px; margin-top: 3px; margin-bottom: 15px; margin-right: 10px;  }
.S2 { min-height: 0px; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S3 { line-height: 21px; min-height: 17px; white-space: pre-wrap; font-family: Helvetica, Arial, sans-serif; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px;  }
.S4 { font-family: Helvetica, Arial, sans-serif; margin-left: 0px; margin-top: 10px; margin-bottom: 20px; margin-right: 0px;  }
.S5 { text-align: left; line-height: 21px; white-space: pre-wrap; white-space: pre-wrap; margin-left: 56px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S6 { margin-left: 3px; margin-top: 10px; margin-bottom: 4px; margin-right: 3px;  }
.S7 { line-height: 15.5926666259766px; min-height: 18px; white-space: nowrap; font-size: 12.6666669845581px; white-space: nowrap; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S8 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(34, 139, 34); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 45px;  }
.S9 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 45px;  }
.S10 { color: rgb(64, 64, 64); margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S11 { margin-left: 3px; margin-top: 4px; margin-bottom: 4px; margin-right: 3px;  }
.S12 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S13 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(0, 0, 255); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S14 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(0, 0, 255); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 45px;  }
.S15 { margin-left: 3px; margin-top: 4px; margin-bottom: 10px; margin-right: 3px;  }
.S16 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(160, 32, 240); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S17 { line-height: 21px; min-height: 17px; white-space: pre-wrap; font-family: Helvetica, Arial, sans-serif; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px;  }
.S18 { text-align: center; line-height: 21px; min-height: 17px; white-space: pre-wrap; font-family: Helvetica, Arial, sans-serif; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px;  }
.S19 { margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px;  }
.S20 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(160, 32, 240); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 45px;  }

.LineNodeBlock {margin: 10px 0 10px 0;}
.LineNodeBlock+.paragraphNode {margin-top: 10px;}
.lineNode {padding-left: 10px; background-color: #F7F7F7; border-left: 1px solid #E9E9E9; border-right: 1px solid #E9E9E9;}
.inlineWrapper:first-child .lineNode,.inlineWrapper.outputs+.inlineWrapper .lineNode {padding-top: 5px; border-top: 1px solid #E9E9E9;}
.inlineWrapper:last-child .lineNode,.inlineWrapper.outputs .lineNode {padding-bottom: 5px; border-bottom: 1px solid #E9E9E9;}
.lineNode .textBox {white-space: pre;}
.outputGroup {margin: 2px 0 2px 0; padding: 2px 2px 2px 4px;}
.outputRegion {}
.outputParagraph {color: rgba(64, 64, 64, 1); padding: 10px 0 6px 17px; background: white; overflow-x: hidden;}
.inlineWrapper:last-child .outputParagraph {border-bottom-left-radius: 4px; border-bottom-right-radius: 4px;}
.outputParagraph:empty {margin: 0;}
.inlineElement .symbolicElement {}
.embeddedOutputsSymbolicElement .MathEquation {margin-top: 5px; margin-bottom: 5px;}
.embeddedOutputsSymbolicElement .MathEquation.displaySymbolicElement {margin-left: 15px;}
.embeddedOutputsSymbolicElement .MathEquation.inlineSymbolicElement {margin-left: 5px;}
.embeddedOutputsSymbolicElement {overflow-x: auto; overflow-y: hidden;}
.embeddedOutputsSymbolicElement { overflow: initial !important;}
.embeddedOutputsTextElement,.embeddedOutputsVariableStringElement {font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px; white-space: pre; word-wrap: initial; min-height: 18px; max-height: 250px; overflow: auto;}
.textElement {padding-top: 3px;}
.embeddedOutputsTextElement.inlineElement {}
.inlineElement .textElement {}
.embeddedOutputsTextElement,.embeddedOutputsVariableStringElement { max-height: none !important; overflow: initial !important;}
.veSpecifier {}
.veContainer {}
.veSpecifierBox {height: 400px; width: 500px;}
.veSpecifier .veTable {padding-top: 3px; padding-bottom: 4px;}
.veSpecifierBox .veSpecifier .veContainer {position: relative; width: 100%; height: 370px;}
.veSpecifierBox .dijitDialogPaneContent {width: 97% !important; height: 88% !important;}
.veSpecifier .veTable .rowHeadersWrapper {padding-bottom: 0;}
.veSpecifier .veTable .scroller .variableEditorRenderers {padding-right: 3px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none;}
.veVariableValueSummary {display: inline-block;}
.veSpecifier .veTable .topHeaderWrapper,.veSpecifier .veTable .bottomRowHeaderWrapper {visibility: hidden; z-index: 0;}
.veMetaSummary {font-style: italic;}
.veSpecifier .veTable .scroller {overflow: hidden;}
.veSpecifier .veTable:hover .scroller {overflow: auto;}
.veSpecifier .veVariableName,.veSpecifier .veDimensionFont {font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px;}
.veSpecifier .veVariableName {padding-top: 3px;}
.veSpecifier .veDimensionFont {font-style: italic; color: #9A9A9A;}
.veSpecifier .scroller::-webkit-scrollbar-track {background-color: white;}
.veSpecifier .scroller::-webkit-scrollbar-corner {background-color: white;}
.veSpecifier .veTable .topRowHeaderWrapper {border: none; background-color: #F8F9FA;}
.veSpecifier .mw_type_ListBase.showCellBorders,.veSpecifier .veTable .topHeaderWrapper,.veSpecifier .veTable .bottomRowHeaderWrapper,.veSpecifier .veTable .verticalScrollSpacer,.veSpecifier .veTable .horizontalScrollSpacer {border: none;}
.veSpecifier .veTable .dataScrollerNode {border: 1px solid #BFBFBF;}
.veSpecifier .veTable .columnHeaderNode,.veSpecifier .veTable .rowHeaderNode,.veSpecifier .veTable .dataBody {font-family: Arial; font-size: 13px;}
.veSpecifier .veTable .columnHeaderNode,.veSpecifier .veTable .rowHeaderNode {color: #7F7F7F;}
.veSpecifier .veTable .dataBody {color: #000000;}
.veSpecifier .veTable .columnHeaderNode .cell .drag,.veSpecifier .veTable .columnHeaderNode .cell .header,.veSpecifier .veTable .topHeaderWrapper,.veSpecifier .veTable .bottomRowHeaderWrapper {background-color: #F8F9FA;}
.veSpecifier .veTable .columnHeaderNode .cell .dragBorder {border-right: 1px solid #F8F9FA;}
.veSpecifier .veTable .rowHeaderNode .cell {padding-top: 3px; text-align: center; border-bottom: 1px solid #F8F9FA;}
.veSpecifier .veTable .dataBody .cell .plainText {text-align: right;}
.veSpecifier .veTable .dataBody .row .cell {border-bottom: 1px solid #E9E9E9; border-right: 1px solid #E9E9E9;}
.embeddedOutputsVariableElement {font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px; white-space: pre-wrap; word-wrap: break-word; min-height: 18px; max-height: 250px; overflow: auto;}
.variableElement {}
.embeddedOutputsVariableElement.inlineElement {}
.inlineElement .variableElement {}
.variableValue { width: 100% !important; }
.embeddedOutputsMatrixElement {min-height: 18px; box-sizing: border-box; font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px;}
.matrixElement .variableValue {white-space: pre; display: inline-block; vertical-align: top; overflow: hidden;}
.embeddedOutputsMatrixElement.inlineElement {}
.embeddedOutputsMatrixElement.inlineElement .topHeaderWrapper {display: none;}
.embeddedOutputsMatrixElement.inlineElement .veTable .body {padding-top: 0 !important; max-height: 100px;}
.embeddedOutputsMatrixElement.inlineElement .veVariableName {padding-top: 0;}
.inlineElement .matrixElement {max-height: 300px;}
.embeddedOutputsMatrixElement .matrixElement .valueContainer {white-space: nowrap; padding-top: 10px; margin-bottom: 3px;}
.embeddedOutputsMatrixElement .matrixElement .valueContainer .horizontalEllipsis.hide,.embeddedOutputsMatrixElement .matrixElement .verticalEllipsis.hide {display: none;}
.embeddedOutputsMatrixElement .matrixElement .valueContainer .horizontalEllipsis {margin-bottom: -3px;}
.matrixElement { max-height: none !important; }
.dijitTooltipDialog .dijitTooltipContainer .dijitTooltipContents .alertPlugin-alertMessage {min-width: 12px; max-width: 400px; max-height: 300px; overflow: auto;}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar {width: 11px; height: 11px;}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-track {background-color: rgba(0, 0, 0, 0);}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-corner {background-color: rgba(0, 0, 0, 0);}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-thumb {border-radius: 7px; background-color: rgba(0, 0, 0, 0.1); border: 2px solid rgba(0, 0, 0, 0); background-clip: padding-box;}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-thumb:hover {background-color: rgba(0, 0, 0, 0.2);}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-thumb {background-color: rgba(0, 0, 0, 0);}
.dijitTooltipDialog .alertPlugin-alertMessage:hover::-webkit-scrollbar-thumb {background-color: rgba(0, 0, 0, 0.1);}
.dijitTooltipDialog .alertPlugin-alertMessage:hover::-webkit-scrollbar-thumb:hover {background-color: rgba(0, 0, 0, 0.2);}
.alertPlugin-alertLine {position: absolute; display: initial; width: 40px; text-align: right; cursor: text;}
.alertPlugin-onTextLine {visibility: hidden;}
.alertPlugin-hasTooltip .alertPlugin-warningImg,.alertPlugin-hasTooltip .alertPlugin-errorImg {cursor: pointer;}
.alertPlugin-isStale {-webkit-filter: opacity(0.4) grayscale(80%); filter: opacity(0.4) grayscale(80%);}
.alertPlugin-alertLine .alertPlugin-errorElement {display: inline-block; margin-right: 4px;}
.alertPlugin-errorImg {position: relative; display: inline-block; background-color: rgb(204, 55, 41); width: 14px; height: 14px; margin-top: 1px; -webkit-border-radius: 7px;}
.alertPlugin-alertLine .alertPlugin-warningElement {display: inline-block; margin-right: 3px;}
.alertPlugin-warningImg {position: relative; display: inline-block; width: 16px; height: 15px; overflow: hidden;}
.diagnosticMessage-wrapper {font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px;}
.diagnosticMessage-wrapper.diagnosticMessage-warningType {color: rgb(255,100,0);}
.diagnosticMessage-wrapper.diagnosticMessage-warningType a {color: rgb(255,100,0); text-decoration: underline;}
.diagnosticMessage-wrapper.diagnosticMessage-errorType {color: rgb(230,0,0);}
.diagnosticMessage-wrapper.diagnosticMessage-errorType a {color: rgb(230,0,0); text-decoration: underline;}
.diagnosticMessage-wrapper .diagnosticMessage-messagePart {white-space: pre-wrap;}
.diagnosticMessage-wrapper .diagnosticMessage-stackPart {white-space: pre;}
.embeddedOutputsWarningElement{min-height: 18px; max-height: 250px; overflow: auto;}
.embeddedOutputsWarningElement.inlineElement {}
.embeddedOutputsErrorElement {min-height: 18px; max-height: 250px; overflow: auto;}
.embeddedOutputsErrorElement.inlineElement {}
.alertPlugin-warningImg {background-image: url()}
.alertPlugin-errorImg {background-image: url()}
</style>
</head>
<body>
<div class="content"><div class="SectionBlock containment"><h1 class="S1"><span class="S2">实用计算方法实验一——三次样条插值</span></h1>
<p class="S3"><span class="S2">姓名：林国瑞</span></p>
<p class="S3"><span class="S2">学号：9151010F0118</span></p>
<ol class="S4"><li class="S5"><span class="S0">自然边界条件，S``(0.2)=S``(1.0)=0</span></li>
<li class="S5"><span class="S0">第一种边界条件S`(0.2)=0.20271，S``(1.0)=,1.55741</span></li>
<li class="S5"><span class="S0">附录：追赶法解三对角矩阵</span></li>
</ol>
<p class="S3"><span class="S2"></span></p>
<h2 class="S3"><span class="S2">1.自然边界条件</span></h2>
<p class="S3"><span class="S2">请输入对应序号：&gt;&gt; 1</span></p>
<p class="S3"><span class="S2">请输入f(a)的二阶导数值：0</span></p>
<p class="S3"><span class="S2">请输入f(b)的二阶导数值：0</span></p>
<div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%三次样条差值-matlab通用程序 - zhangxiaolu2015的专栏 - CSDN博客  https://blog.csdn.net/zhangxiaolu2015/article/details/42744823</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%【图文】三次样条插值算法详解_百度文库  https://wenku.baidu.com/view/14423f2e1711cc7931b716ae.html与课堂使用PPT一致。</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">clc</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">clear</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">% x=input('请按照格式[x1,x2,x3...]格式输入y=f(x)函数已知点的横坐标xi=');  %三次样条差值函数                                </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">% y=input('请按照格式[y1,y2,y3...]格式输入y=f(x)函数已知点对应的纵坐标yi=');</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">x=[0.2 0.4 0.6 0.8 1.0];</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">y=[0.9798652  0.9177710 0.8080348 0.6386093 0.38433785];</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">x</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement scrollableOutput" data-width="716" style="width: 716px;"><div class="textElement"><div>x = </div>
<div>&nbsp;&nbsp; 0.200000000000000&nbsp;&nbsp; 0.400000000000000&nbsp;&nbsp; 0.600000000000000&nbsp;&nbsp; 0.800000000000000&nbsp;&nbsp; 1.000000000000000<br/><br/></div>
</div>
</div>
</div>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">y</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement scrollableOutput" data-width="716" style="width: 716px;"><div class="textElement"><div>y = </div>
<div>&nbsp;&nbsp; 0.979865200000000&nbsp;&nbsp; 0.917771000000000&nbsp;&nbsp; 0.808034800000000&nbsp;&nbsp; 0.638609300000000&nbsp;&nbsp; 0.384337850000000<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="S0"></p>
<div class="SectionBlock containment"><div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">n=size(x,2);   </span><span class="S8">%特别注意，matlab中的矩阵编号是从1开始的，而教材上的矩阵编号是从0开始的，即本程序n比PPT上n值大1</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">for </span><span class="S12">k=2:n      </span><span class="S8">%计算h(i)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  </span><span class="S12">h</span><span class="S9">(k-1)=x(k)-x(k-1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S14">end</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">h</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>h = </div>
<div>&nbsp;&nbsp; 0.200000000000000&nbsp;&nbsp; 0.200000000000000&nbsp;&nbsp; 0.200000000000000&nbsp;&nbsp; 0.200000000000000<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="S0"></p>
<div class="SectionBlock containment"><div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">for </span><span class="S12">k=1:(n-2)          </span><span class="S8">%计算μ和λ</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12"> </span><span class="S12">mu</span><span class="S9">(k)=h(k)/(h(k)+h(k+1));</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12"> </span><span class="S12">lambda</span><span class="S9">(k)=1-mu(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S14">end</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">mu</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>mu = </div>
<div>&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000<br/><br/></div>
</div>
</div>
</div>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">lambda</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>lambda = </div>
<div>&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="S0"></p>
<div class="SectionBlock containment"><div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%% </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">% 以上无论是M还是m关系式矩阵通用。</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">for </span><span class="S9">k=1:(n-2)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  </span><span class="S12">g</span><span class="S12">(k)=3*(lambda(k)*(y(k+1)-y(k))/h(k)+mu(k)*(y(k+2)-y(k+1))/h(k+1));      </span><span class="S8">%计算g(1)到g(n-2)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S14">end</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">g</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>g = </div>
<div>&nbsp;&nbsp;-1.288728000000000&nbsp;&nbsp;-2.093712750000000&nbsp;&nbsp;-3.177727125000001<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="S0"></p>
<div class="SectionBlock containment active"><div class="LineNodeBlock contiguous"><div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S12">fprintf(</span><span class="S16">'边界条件类型选择:\n1.已知f(a)和f(b)的二阶导数\n2.已知f(a)和f(b)的一阶导数\n'</span><span class="S9">);</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsTextElement" data-width="716" style="width: 716px;"><div class="textElement">边界条件类型选择:<br/>1.已知f(a)和f(b)的二阶导数<br/>2.已知f(a)和f(b)的一阶导数</div>
</div>
</div>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">in=input(</span><span class="S16">'请输入对应序号：'</span><span class="S9">);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">if </span><span class="S9">in==1</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    in</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    M(1)=input(</span><span class="S16">'请输入f(a)的二阶导数值：'</span><span class="S9">);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    M(n)=input(</span><span class="S16">'请输入f(b)的二阶导数值：'</span><span class="S9">);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    M(1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    M(n)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    A=zeros(n,n);     </span><span class="S8">%构造追赶法所需的A和b</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=2:(n-1)          </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k+1)=mu(k-1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k-1)=lambda(k-1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(1,1)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(1,2)=1;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(end,end)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(end,end-1)=1;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b=zeros(n,1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=2:(n-1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        b(k,1)=g(k-1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b(1,1)=3*((y(2)-y(1))/h(1)-2*h(1)*M(1));</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b(n,1)=3*((y(n)-y(n-1))/h(n-1)+2*h(n-1)*M(n));</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">   </span><span class="S8">%b=b';</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    m=zhuigan(A,b);      </span><span class="S8">%利用追赶法求解成功，这里的参数b形式为列向量</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">  </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">elseif </span><span class="S9">in==2</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%     y0=input('请输入f(a)的一阶导数值：');</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%     yn=input('请输入f(b)的一阶导数值：');</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    y0=0.20271;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    yn=1.55741;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    A=zeros(n-2,n-2);    </span><span class="S8">%构造追赶法所需的A和b</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=2:(n-3)           </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k+1)=mu(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k-1)=lambda(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(1,1)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(1,2)=mu(1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(end,end)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(end,end-1)=lambda(n-2);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b=zeros(n-2,1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=2:(n-3)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">      b(k,1)=g(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b(1,1)=g(1)-lambda(1)*y0;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b(end,1)=g(n-2)-mu(n-2)*yn;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S8">%b=b';</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    m=zhuigan(A,b);</span><span class="S8">%利用追赶法求解</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m(1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m(2)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S8">%这里解出m(1)至m(n-2),为能代入带一阶导数的分段三次埃米尔特插值多项式，要对m进行调整</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=(n-2):-1:1</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        m(k+1)=m(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m(1)=y0;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m(n)=yn;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S14">end</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>in = </div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; 1<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>ans = </div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; 0<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>ans = </div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; 0<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement scrollableOutput" data-width="716" style="width: 716px;"><div class="textElement"><div>A = </div>
<div>&nbsp;&nbsp; 2.000000000000000&nbsp;&nbsp; 1.000000000000000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<br/>&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 2.000000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 2.000000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 2.000000000000000&nbsp;&nbsp; 0.500000000000000<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; 1.000000000000000&nbsp;&nbsp; 2.000000000000000<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>b = </div>
<div>&nbsp;&nbsp;-0.931413000000000<br/>&nbsp;&nbsp;-1.288728000000000<br/>&nbsp;&nbsp;-2.093712750000000<br/>&nbsp;&nbsp;-3.177727125000001<br/>&nbsp;&nbsp;-3.814071750000002<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>c = </div>
<div>&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 1.000000000000000<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>a = </div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 2<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px;"><div class="textElement"><div>b = </div>
<div>&nbsp;&nbsp; 1.000000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000<br/><br/></div>
</div>
</div>
</div>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">m</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement scrollableOutput" data-width="716" style="width: 716px;"><div class="textElement"><div>m = </div>
<div>&nbsp;&nbsp;-0.260406825892857&nbsp;&nbsp;-0.410599348214286&nbsp;&nbsp;-0.674651781250000&nbsp;&nbsp;-1.078219026785715&nbsp;&nbsp;-1.367926361607143<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
<p class="S17"><span class="S2"></span></p>
<p class="S18"><span style="vertical-align:-15"><img src="" width="718.5" height="43.5"/></span></p>
<p class="S3"><span class="S2"></span></p>
<div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S9"></span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%三转角公式</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">for </span><span class="S9">k=1:(n-1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  clear </span><span class="S20">S1</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  syms </span><span class="S20">X</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  S1=(1-2*(X-x(k))/(-h(k)))*((X-x(k+1))/(h(k)))^2*y(k)+</span><span class="S13">...</span><span class="S8">                              </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    (X-x(k))*((X-x(k+1))/(h(k)))^2*m(k)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    (1-2*(X-x(k+1))/(h(k)))*((X-x(k))/(h(k)))^2*y(k+1)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    (X-x(k+1))*((X-x(k))/(h(k)))^2*m(k+1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  fprintf(</span><span class="S16">'当%d=&lt;X=&lt;%d时\n'</span><span class="S9">,x(k),x(k+1));</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">  S=expand(S1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">  vpa(S)</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S14">end</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsTextElement" data-width="716" style="width: 716px;"><div class="textElement">当2.000000e-01=&lt;X=&lt;4.000000e-01时</div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement" data-width="716" style="width: 716px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">S =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="462.5" height="28.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement scrollableOutput" data-width="716" style="width: 716px; max-height: 59px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">ans =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="1194.5" height="20.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsTextElement" data-width="716" style="width: 716px;"><div class="textElement">当4.000000e-01=&lt;X=&lt;6.000000e-01时</div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement" data-width="716" style="width: 716px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">S =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="455.5" height="28.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement scrollableOutput" data-width="716" style="width: 716px; max-height: 59px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">ans =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="1199" height="20.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsTextElement" data-width="716" style="width: 716px;"><div class="textElement">当6.000000e-01=&lt;X=&lt;8.000000e-01时</div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement" data-width="716" style="width: 716px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">S =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="468" height="28.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement scrollableOutput" data-width="716" style="width: 716px; max-height: 59px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">ans =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="1194.5" height="20.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsTextElement" data-width="716" style="width: 716px;"><div class="textElement">当8.000000e-01=&lt;X=&lt;1时</div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement" data-width="716" style="width: 716px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">S =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="455.5" height="28.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement scrollableOutput" data-width="716" style="width: 716px; max-height: 59px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">ans =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="1190.5" height="20.5" style="vertical-align: bottom;"/></span></div>
</div>
</div>
</div>
</div>
<p class="S17"><span class="S2">自然边界条件插值结果</span></p>
<p class="S3"><span class="S2">x=[0.2 0.4 0.6 0.8 1.0];</span></p>
<p class="S3"><span class="S2">y=[0.9798652  0.9177710 0.8080348 0.6386093 0.38433785];</span></p>
<div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">x=0.2:0.01:1.0;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">y=(-1.2516043526785716744065268812847*x.^3 + 0.75096261160714328219967228505993*x.^2 - 0.4105993482142858419514652723592*x+ 1.041959400000000002250999386888).*(x&lt;0.4)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    (0.3027717633928575513557746035076*x.^3 - 1.1142887276785712336035771841125*x.^2 + 0.33550118749999974232522959027847*x + 0.94247932857142862062005406187382).*(x&gt;=0.4 &amp; x&lt;=0.6)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    (-1.4653952008928577965818362827122*x.^3 + 2.0684118080357133395708046919026*x.^2 - 1.5741191339285691697114089038223*x + 1.3244033928571420366537836343923).*(x&gt;0.6 &amp; x&lt;=0.8)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    (2.4142277901785635929599038718152*x.^3 - 7.2426833705356929993257608657586*x.^2 + 5.8747570089285519046029548917431*x - 0.66196357857142251734927640427486).*(x&gt;0.8 &amp; x&lt;=1.0);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">plot(x,y);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">legend(</span><span class="S16">'自然条件'</span><span class="S9">)</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S12">grid </span><span class="S16">on</span><span class="S9">;</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsFigure" style="max-height: 800px; width: 716px;"><div class="figureElement"><img class="figureImage" draggable="false" src=""/></div>
</div>
</div>
</div>
</div>
<p class="S17"><br/><span class="S2"></span></p>
</div>
</div>
<div class="content"><div class="SectionBlock containment active"><ol class="S4">
</ol>
<p class="S3"><span class="S2"></span></p>
<h2 class="S3"><span class="S2">2.第一种边界条件</span></h2>
<p class="S3"><span class="S2">请输入对应序号：&gt;&gt; 2</span></p>
<div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%三次样条差值-matlab通用程序 - zhangxiaolu2015的专栏 - CSDN博客  https://blog.csdn.net/zhangxiaolu2015/article/details/42744823</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%【图文】三次样条插值算法详解_百度文库  https://wenku.baidu.com/view/14423f2e1711cc7931b716ae.html与课堂使用PPT一致。</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">clc</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">clear</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">% x=input('请按照格式[x1,x2,x3...]格式输入y=f(x)函数已知点的横坐标xi=');  %三次样条差值函数                                </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">% y=input('请按照格式[y1,y2,y3...]格式输入y=f(x)函数已知点对应的纵坐标yi=');</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">x=[0.2 0.4 0.6 0.8 1.0];</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">y=[0.9798652  0.9177710 0.8080348 0.6386093 0.38433785];</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">x</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement scrollableOutput" data-width="716" style="width: 716px; opacity: 1;"><div class="textElement"><div>x = </div>
<div>&nbsp;&nbsp; 0.200000000000000&nbsp;&nbsp; 0.400000000000000&nbsp;&nbsp; 0.600000000000000&nbsp;&nbsp; 0.800000000000000&nbsp;&nbsp; 1.000000000000000<br/><br/></div>
</div>
</div>
</div>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">y</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement scrollableOutput" data-width="716" style="width: 716px; opacity: 1;"><div class="textElement"><div>y = </div>
<div>&nbsp;&nbsp; 0.979865200000000&nbsp;&nbsp; 0.917771000000000&nbsp;&nbsp; 0.808034800000000&nbsp;&nbsp; 0.638609300000000&nbsp;&nbsp; 0.384337850000000<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="S0"></p>
<div class="SectionBlock containment"><div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">n=size(x,2);   </span><span class="S8">%特别注意，matlab中的矩阵编号是从1开始的，而教材上的矩阵编号是从0开始的，即本程序n比PPT上n值大1</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">for </span><span class="S12">k=2:n      </span><span class="S8">%计算h(i)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  </span><span class="S12">h</span><span class="S9">(k-1)=x(k)-x(k-1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S14">end</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">h</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px; opacity: 1;"><div class="textElement"><div>h = </div>
<div>&nbsp;&nbsp; 0.200000000000000&nbsp;&nbsp; 0.200000000000000&nbsp;&nbsp; 0.200000000000000&nbsp;&nbsp; 0.200000000000000<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="S0"></p>
<div class="SectionBlock containment"><div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">for </span><span class="S12">k=1:(n-2)          </span><span class="S8">%计算μ和λ</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12"> </span><span class="S12">mu</span><span class="S9">(k)=h(k)/(h(k)+h(k+1));</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12"> </span><span class="S12">lambda</span><span class="S9">(k)=1-mu(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S14">end</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">mu</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px; opacity: 1;"><div class="textElement"><div>mu = </div>
<div>&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000<br/><br/></div>
</div>
</div>
</div>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">lambda</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px; opacity: 1;"><div class="textElement"><div>lambda = </div>
<div>&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="S0"></p>
<div class="SectionBlock containment"><div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%% </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">% 以上无论是M还是m关系式矩阵通用。</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">for </span><span class="S9">k=1:(n-2)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  </span><span class="S12">g</span><span class="S12">(k)=3*(lambda(k)*(y(k+1)-y(k))/h(k)+mu(k)*(y(k+2)-y(k+1))/h(k+1));      </span><span class="S8">%计算g(1)到g(n-2)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S14">end</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">g</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="width: 716px; opacity: 1;"><div class="textElement"><div>g = </div>
<div>&nbsp;&nbsp;-1.288728000000000&nbsp;&nbsp;-2.093712750000000&nbsp;&nbsp;-3.177727125000001<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="S0"></p>
<div class="SectionBlock containment"><div class="LineNodeBlock contiguous"><div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S12">fprintf(</span><span class="S16">'边界条件类型选择:\n1.已知f(a)和f(b)的二阶导数\n2.已知f(a)和f(b)的一阶导数\n'</span><span class="S9">);</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsTextElement" data-width="716" style="width: 716px; opacity: 1;"><div class="textElement">边界条件类型选择:<br/>1.已知f(a)和f(b)的二阶导数<br/>2.已知f(a)和f(b)的一阶导数</div>
</div>
</div>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">in=input(</span><span class="S16">'请输入对应序号：'</span><span class="S9">);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">if </span><span class="S9">in==1</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    in</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    M(1)=input(</span><span class="S16">'请输入f(a)的二阶导数值：'</span><span class="S9">);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    M(n)=input(</span><span class="S16">'请输入f(b)的二阶导数值：'</span><span class="S9">);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    M(1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    M(n)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    A=zeros(n,n);     </span><span class="S8">%构造追赶法所需的A和b</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=2:(n-1)          </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k+1)=mu(k-1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k-1)=lambda(k-1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(1,1)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(1,2)=1;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(end,end)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(end,end-1)=1;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b=zeros(n,1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=2:(n-1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        b(k,1)=g(k-1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b(1,1)=3*((y(2)-y(1))/h(1)-2*h(1)*M(1));</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b(n,1)=3*((y(n)-y(n-1))/h(n-1)+2*h(n-1)*M(n));</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">   </span><span class="S8">%b=b';</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    m=zhuigan(A,b);      </span><span class="S8">%利用追赶法求解成功，这里的参数b形式为列向量</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">  </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">elseif </span><span class="S9">in==2</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%     y0=input('请输入f(a)的一阶导数值：');</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%     yn=input('请输入f(b)的一阶导数值：');</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    y0=0.20271;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    yn=1.55741;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    A=zeros(n-2,n-2);    </span><span class="S8">%构造追赶法所需的A和b</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=2:(n-3)           </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k+1)=mu(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        A(k,k-1)=lambda(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(1,1)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(1,2)=mu(1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(end,end)=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A(end,end-1)=lambda(n-2);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    A</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b=zeros(n-2,1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=2:(n-3)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">      b(k,1)=g(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b(1,1)=g(1)-lambda(1)*y0;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b(end,1)=g(n-2)-mu(n-2)*yn;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    b</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S8">%b=b';</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    m=zhuigan(A,b);</span><span class="S8">%利用追赶法求解</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m(1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m(2)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S8">%这里解出m(1)至m(n-2),为能代入带一阶导数的分段三次埃米尔特插值多项式，要对m进行调整</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S13">for </span><span class="S9">k=(n-2):-1:1</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">        m(k+1)=m(k);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    </span><span class="S14">end</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m(1)=y0;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m(n)=yn;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    m</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S14">end</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement"><div>A = </div>
<div>&nbsp;&nbsp; 2.000000000000000&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<br/>&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 2.000000000000000&nbsp;&nbsp; 0.500000000000000<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 2.000000000000000<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement"><div>b = </div>
<div>&nbsp;&nbsp;-1.390083000000000<br/>&nbsp;&nbsp;-2.093712750000000<br/>&nbsp;&nbsp;-3.956432125000001<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement"><div>c = </div>
<div>&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement"><div>a = </div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 2<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement"><div>b = </div>
<div>&nbsp;&nbsp; 0.500000000000000&nbsp;&nbsp; 0.500000000000000<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement"><div>m = </div>
<div>&nbsp;&nbsp;-0.586886647321428&nbsp;&nbsp;-0.432619410714285&nbsp;&nbsp;-1.870061209821429<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement"><div>ans = </div>
<div>&nbsp;&nbsp;-0.586886647321428<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement"><div>ans = </div>
<div>&nbsp;&nbsp;-0.432619410714285<br/><br/></div>
</div>
</div>
<div class="inlineElement embeddedOutputsVariableStringElement scrollableOutput" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement"><div>m = </div>
<div>&nbsp;&nbsp; 0.202710000000000&nbsp;&nbsp;-0.586886647321428&nbsp;&nbsp;-0.432619410714285&nbsp;&nbsp;-1.870061209821429&nbsp;&nbsp; 1.557410000000000<br/><br/></div>
</div>
</div>
</div>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S9">m</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsVariableStringElement scrollableOutput" data-width="716" style="width: 716px; opacity: 1;"><div class="textElement"><div>m = </div>
<div>&nbsp;&nbsp; 0.202710000000000&nbsp;&nbsp;-0.586886647321428&nbsp;&nbsp;-0.432619410714285&nbsp;&nbsp;-1.870061209821429&nbsp;&nbsp; 1.557410000000000<br/><br/></div>
</div>
</div>
</div>
</div>
</div>
<p class="S17"><span class="S2"></span></p>
<p class="S18"><span style="vertical-align:-15"><img src="" width="718.5" height="43.5"/></span></p>
<p class="S3"><span class="S2"></span></p>
<div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S9"></span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S8">%三转角公式</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S13">for </span><span class="S9">k=1:(n-1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  clear </span><span class="S20">S1</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  syms </span><span class="S20">X</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  S1=(1-2*(X-x(k))/(-h(k)))*((X-x(k+1))/(h(k)))^2*y(k)+</span><span class="S13">...</span><span class="S8">                              </span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    (X-x(k))*((X-x(k+1))/(h(k)))^2*m(k)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    (1-2*(X-x(k+1))/(h(k)))*((X-x(k))/(h(k)))^2*y(k+1)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    (X-x(k+1))*((X-x(k))/(h(k)))^2*m(k+1);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">  fprintf(</span><span class="S16">'当%d=&lt;X=&lt;%d时\n'</span><span class="S9">,x(k),x(k+1));</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">  S=expand(S1)</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">  vpa(S)</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S14">end</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsTextElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement">当2.000000e-01=&lt;X=&lt;4.000000e-01时</div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement" data-width="716" style="opacity: 1; width: 716px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">S =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="527.5" height="28.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement scrollableOutput" data-width="716" style="opacity: 1; width: 716px; max-height: 59px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">ans =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="1182" height="20.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsTextElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement">当4.000000e-01=&lt;X=&lt;6.000000e-01时</div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement" data-width="716" style="opacity: 1; width: 716px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">S =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="461" height="28.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement scrollableOutput" data-width="716" style="opacity: 1; width: 716px; max-height: 59px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">ans =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="1199" height="20.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsTextElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement">当6.000000e-01=&lt;X=&lt;8.000000e-01时</div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement" data-width="716" style="opacity: 1; width: 716px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">S =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="495.5" height="28.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement scrollableOutput" data-width="716" style="opacity: 1; width: 716px; max-height: 59px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">ans =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="1194.5" height="20.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsTextElement" data-width="716" style="opacity: 1; width: 716px;"><div class="textElement">当8.000000e-01=&lt;X=&lt;1时</div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement" data-width="716" style="opacity: 1; width: 716px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">S =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="489" height="28.5" style="vertical-align: bottom;"/></span></div>
</div>
<div class="inlineElement embeddedOutputsSymbolicElement scrollableOutput" data-width="716" style="opacity: 1; width: 716px; max-height: 59px;"><div class="symbolicElement"><span class="embeddedOutputsVariableElement">ans =</span><span class="MathEquation Windows inlineSymbolicElement" style="font-size: 15px;"><img src="" width="1174" height="20.5" style="vertical-align: bottom;"/></span></div>
</div>
</div>
</div>
</div>
<h3 class="S17"><span class="S2">第一种边界条件插值结果</span></h3>
<p class="S3"><span class="S2">x=[0.2 0.4 0.6 0.8 1.0];</span></p>
<p class="S3"><span class="S2">y=[0.9798652  0.9177710 0.8080348 0.6386093 0.38433785];</span></p>
<div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">x=0.2:0.01:1.0;</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">y=(5.919133816964285111694721308595*x.^3 - 7.3012120535714277966832241872908*x.^2 + 2.4128987633928569052699231178849*x + 0.74198085892857144167322758221417).*(x&lt;0.4)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    (1.9463985491071394973161545749463*x.^3 - 2.5339297321428516651664608616557*x.^2 + 0.50598583482142589495822448952822*x + 0.99623591607142898407545317240874).*(x&gt;=0.4 &amp; x&lt;=0.6)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">    (-15.210640513392861827846047617641*x.^3 + 28.348740580357150720125503085001*x.^2 - 18.023616352678575536216953878466*x + 4.7021563535714292703104888460075).*(x&gt;0.6 &amp; x&lt;=0.8)+</span><span class="S14">...</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">    (55.75158225446428805760490376997*x.^3 - 141.96059406250000511917619405722*x.^2 + 118.22385136160714602659993488487*x - 31.630501703571428984140823104099).*(x&gt;0.8 &amp; x&lt;=1.0);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S9">plot(x,y);</span></p>
</div>
<div class="inlineWrapper"><p class="S7 lineNode"><span class="S12">legend(</span><span class="S16">'第一种边界条件'</span><span class="S9">)</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S7 lineNode"><span class="S12">grid </span><span class="S16">on</span><span class="S9">;</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsFigure" style="max-height: 800px; opacity: 1; width: 716px;"><div class="figureElement"><img class="figureImage" draggable="false" src=""/></div>
<div class="figureElement"><br/></div>
<div class="figureElement"><br/></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="content"><div class="SectionBlock containment active"><div class="LineNodeBlock contiguous"><div class="inlineWrapper outputs">
</div>
</div>
</div>
</div>




<!-- 
##### SOURCE BEGIN #####
clear
clc
x=0.2:0.01:1.0;
y=(-1.2516043526785716744065268812847*x.^3 + 0.75096261160714328219967228505993*x.^2 - 0.4105993482142858419514652723592*x+ 1.041959400000000002250999386888).*(x<0.4)+...
    (0.3027717633928575513557746035076*x.^3 - 1.1142887276785712336035771841125*x.^2 + 0.33550118749999974232522959027847*x + 0.94247932857142862062005406187382).*(x>=0.4 & x<=0.6)+...
    (-1.4653952008928577965818362827122*x.^3 + 2.0684118080357133395708046919026*x.^2 - 1.5741191339285691697114089038223*x + 1.3244033928571420366537836343923).*(x>0.6 & x<=0.8)+...
    (2.4142277901785635929599038718152*x.^3 - 7.2426833705356929993257608657586*x.^2 + 5.8747570089285519046029548917431*x - 0.66196357857142251734927640427486).*(x>0.8 & x<=1.0);
x=0.2:0.01:1.0;
y1=(5.919133816964285111694721308595*x.^3 - 7.3012120535714277966832241872908*x.^2 + 2.4128987633928569052699231178849*x + 0.74198085892857144167322758221417).*(x<0.4)+...
    (1.9463985491071394973161545749463*x.^3 - 2.5339297321428516651664608616557*x.^2 + 0.50598583482142589495822448952822*x + 0.99623591607142898407545317240874).*(x>=0.4 & x<=0.6)+...
    (-15.210640513392861827846047617641*x.^3 + 28.348740580357150720125503085001*x.^2 - 18.023616352678575536216953878466*x + 4.7021563535714292703104888460075).*(x>0.6 & x<=0.8)+...
    (55.75158225446428805760490376997*x.^3 - 141.96059406250000511917619405722*x.^2 + 118.22385136160714602659993488487*x - 31.630501703571428984140823104099).*(x>0.8 & x<=1.0);
plot(x,y,x,y1);
legend('自然边界条件','第一种边界条件');
grid on
##### SOURCE END #####
-->


<div class="content"><div class="SectionBlock containment active"><div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">clear</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">clc</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">x=0.2:0.01:1.0;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">y=(-1.2516043526785716744065268812847*x.^3 + 0.75096261160714328219967228505993*x.^2 - 0.4105993482142858419514652723592*x+ 1.041959400000000002250999386888).*(x&lt;0.4)+</span><span class="S5">...</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    (0.3027717633928575513557746035076*x.^3 - 1.1142887276785712336035771841125*x.^2 + 0.33550118749999974232522959027847*x + 0.94247932857142862062005406187382).*(x&gt;=0.4 &amp; x&lt;=0.6)+</span><span class="S5">...</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    (-1.4653952008928577965818362827122*x.^3 + 2.0684118080357133395708046919026*x.^2 - 1.5741191339285691697114089038223*x + 1.3244033928571420366537836343923).*(x&gt;0.6 &amp; x&lt;=0.8)+</span><span class="S5">...</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    (2.4142277901785635929599038718152*x.^3 - 7.2426833705356929993257608657586*x.^2 + 5.8747570089285519046029548917431*x - 0.66196357857142251734927640427486).*(x&gt;0.8 &amp; x&lt;=1.0);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">x=0.2:0.01:1.0;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">y1=(5.919133816964285111694721308595*x.^3 - 7.3012120535714277966832241872908*x.^2 + 2.4128987633928569052699231178849*x + 0.74198085892857144167322758221417).*(x&lt;0.4)+</span><span class="S5">...</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    (1.9463985491071394973161545749463*x.^3 - 2.5339297321428516651664608616557*x.^2 + 0.50598583482142589495822448952822*x + 0.99623591607142898407545317240874).*(x&gt;=0.4 &amp; x&lt;=0.6)+</span><span class="S5">...</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    (-15.210640513392861827846047617641*x.^3 + 28.348740580357150720125503085001*x.^2 - 18.023616352678575536216953878466*x + 4.7021563535714292703104888460075).*(x&gt;0.6 &amp; x&lt;=0.8)+</span><span class="S5">...</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    (55.75158225446428805760490376997*x.^3 - 141.96059406250000511917619405722*x.^2 + 118.22385136160714602659993488487*x - 31.630501703571428984140823104099).*(x&gt;0.8 &amp; x&lt;=1.0);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">plot(x,y,x,y1);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">legend(</span><span class="S6">'自然边界条件'</span><span class="S4">,</span><span class="S6">'第一种边界条件'</span><span class="S3">);</span></p>
</div>
<div class="inlineWrapper outputs"><p class="S2 lineNode"><span class="S4">grid </span><span class="S7">on</span></p>
<div class="outputParagraph"><div class="inlineElement embeddedOutputsFigure" style="max-height: 800px; width: 716px;"><div class="figureElement"><img class="figureImage" draggable="false" src=""/></div>
</div>
</div>
</div>
</div>
<h2 class="S9"><span class="S10">3.附录:追赶法解三对角矩阵</span></h2>
<div class="LineNodeBlock contiguous"><div class="inlineWrapper"><p class="S2 lineNode"><span class="S12">% %科学网—求解三对角线性方程组 Ax = b 的追赶法的MATLAB程序 - 王福昌的博文  http://blog.sciencenet.cn/blog-292361-1009138.html</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S12">% %数值分析 追赶法求解三对角线性方程组 MATLAB实现 - jingmiaa的博客 - CSDN博客  https://blog.csdn.net/jingmiaa/article/details/49660795</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S12">% function [x,y,l,u] = zhuigan(A,d)</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S12">%定义函数 zhuigan</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    n=size(A,1);</span><span class="S12">%此处矩阵A的行数为n</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    nd=size(d,1);</span><span class="S12">%获得矩阵d的行数</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%将矩阵d转化为一个行向量e</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S13">for </span><span class="S3">i=1:n</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">        </span><span class="S4">e</span><span class="S3">(i)=d(i,1);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    n0=size(A,2);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    flag=0;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    k=1;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    c(n-1)=A(end,end-1);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    u=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    a(1)=A(1,1);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    a(n)=A(end,end);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    b(1)=A(1,2);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    m=2;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S13">for </span><span class="S3">i=2:(n-1)</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">        </span><span class="S13">for </span><span class="S3">j=1:n0</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">            </span><span class="S13">if </span><span class="S3">A(i,j)~=0</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">                </span><span class="S13">if </span><span class="S3">flag==0</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">                    c(k)=A(i,j);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">                    k=k+1;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">                    flag=flag+1;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">                </span><span class="S13">elseif </span><span class="S3">flag==1</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">                    a(u)=A(i,j);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">                    u=u+1;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">                    flag=flag+1;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">                </span><span class="S13">elseif </span><span class="S3">flag==2</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">                    </span><span class="S4">b</span><span class="S3">(m)=A(i,j);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">                    m=m+1;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">                    flag=0;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">                    </span><span class="S13">break</span><span class="S3">;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">                </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">            </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">        </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    c</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    a</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    b</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%以上将a,b,c转换成功</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%数组a存储三角矩阵A的主对角线元素，b、c存储主对角线上边下边带宽为1的元素</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%这里的c（1）不是0，这里的c(1)是课本《数值计算方法与算法（第三版）》张韵华主编第91页的c(2)</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    n=length(a);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    n1=length(b);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    n2=length(c);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%错误检查</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S13">if </span><span class="S4">n1~=n2</span><span class="S12">%存储矩阵的数组维数错误</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">        error(</span><span class="S6">'MATLAB:Crout:不是三对角矩阵，参数数组中元素个数错误.'</span><span class="S3">);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S13">elseif </span><span class="S3">n~=n1+1</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">        error(</span><span class="S6">'MATLAB:Crout:不是三对角矩阵，参数数组中元素个数错误.'</span><span class="S3">);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">   </span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%初始化</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    L=zeros(n);</span><span class="S12">%生成n*n的全零矩阵</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    U=zeros(n);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    u=1:n;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    v=1:n-1;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    x=1:n;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    y=1:n;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">   </span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%追赶法程序主体</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    u(1)=a(1);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S13">for </span><span class="S3">i=1:n-1</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">        v(i)=b(i)/u(i);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">        u(i+1)=a(i+1)-c(i)*v(i);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%正解y</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    y(1)=e(1)/u(1);</span><span class="S12">%用x存储y</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S13">for </span><span class="S3">i=2:n</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">        y(i)=(e(i)-c(i-1)*y(i-1))/u(i);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%倒解x</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">    x(n)=y(n);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S13">for </span><span class="S3">i=(n-1):-1:1</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">        x(i)=y(i)-v(i)*x(i+1);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S12">%L,U矩阵</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S13">for </span><span class="S3">i=1:n</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">        L(i,i)=u(i);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">        U(i,i)=1;</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S5">end</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S4">    </span><span class="S13">for</span><span class="S13"> </span><span class="S3">i=1:n-1</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">        L(i+1,i)=c(i);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S3">        U(i,i+1)=v(i);</span></p>
</div>
<div class="inlineWrapper"><p class="S2 lineNode"><span class="S12">end %end of function</span></p>
</div>
</div>
</div>
</div>
<!-- 
##### SOURCE BEGIN #####
clear
clc
x=0.2:0.01:1.0;
y=(-1.2516043526785716744065268812847*x.^3 + 0.75096261160714328219967228505993*x.^2 - 0.4105993482142858419514652723592*x+ 1.041959400000000002250999386888).*(x<0.4)+...
    (0.3027717633928575513557746035076*x.^3 - 1.1142887276785712336035771841125*x.^2 + 0.33550118749999974232522959027847*x + 0.94247932857142862062005406187382).*(x>=0.4 & x<=0.6)+...
    (-1.4653952008928577965818362827122*x.^3 + 2.0684118080357133395708046919026*x.^2 - 1.5741191339285691697114089038223*x + 1.3244033928571420366537836343923).*(x>0.6 & x<=0.8)+...
    (2.4142277901785635929599038718152*x.^3 - 7.2426833705356929993257608657586*x.^2 + 5.8747570089285519046029548917431*x - 0.66196357857142251734927640427486).*(x>0.8 & x<=1.0);
x=0.2:0.01:1.0;
y1=(5.919133816964285111694721308595*x.^3 - 7.3012120535714277966832241872908*x.^2 + 2.4128987633928569052699231178849*x + 0.74198085892857144167322758221417).*(x<0.4)+...
    (1.9463985491071394973161545749463*x.^3 - 2.5339297321428516651664608616557*x.^2 + 0.50598583482142589495822448952822*x + 0.99623591607142898407545317240874).*(x>=0.4 & x<=0.6)+...
    (-15.210640513392861827846047617641*x.^3 + 28.348740580357150720125503085001*x.^2 - 18.023616352678575536216953878466*x + 4.7021563535714292703104888460075).*(x>0.6 & x<=0.8)+...
    (55.75158225446428805760490376997*x.^3 - 141.96059406250000511917619405722*x.^2 + 118.22385136160714602659993488487*x - 31.630501703571428984140823104099).*(x>0.8 & x<=1.0);
plot(x,y,x,y1);
legend('自然边界条件','第一种边界条件');
grid on
%% 
% 3.附录:追赶法解三对角矩阵

% %科学网—求解三对角线性方程组 Ax = b 的追赶法的MATLAB程序 - 王福昌的博文  http://blog.sciencenet.cn/blog-292361-1009138.html
% %数值分析 追赶法求解三对角线性方程组 MATLAB实现 - jingmiaa的博客 - CSDN博客  https://blog.csdn.net/jingmiaa/article/details/49660795
% function [x,y,l,u] = zhuigan(A,d)
%定义函数 zhuigan
    n=size(A,1);%此处矩阵A的行数为n
    nd=size(d,1);%获得矩阵d的行数
    %将矩阵d转化为一个行向量e
    for i=1:n
        e(i)=d(i,1);
    end
    n0=size(A,2);
    flag=0;
    k=1;
    c(n-1)=A(end,end-1);
    u=2;
    a(1)=A(1,1);
    a(n)=A(end,end);
    b(1)=A(1,2);
    m=2;
    for i=2:(n-1)
        for j=1:n0
            if A(i,j)~=0
                if flag==0
                    c(k)=A(i,j);
                    k=k+1;
                    flag=flag+1;
                elseif flag==1
                    a(u)=A(i,j);
                    u=u+1;
                    flag=flag+1;
                elseif flag==2
                    b(m)=A(i,j);
                    m=m+1;
                    flag=0;
                    break;
                end
            end
        end
    end
    c
    a
    b
    %以上将a,b,c转换成功
    %数组a存储三角矩阵A的主对角线元素，b、c存储主对角线上边下边带宽为1的元素
    %这里的c（1）不是0，这里的c(1)是课本《数值计算方法与算法（第三版）》张韵华主编第91页的c(2)
    n=length(a);
    n1=length(b);
    n2=length(c);
    %错误检查
    if n1~=n2%存储矩阵的数组维数错误
        error('MATLAB:Crout:不是三对角矩阵，参数数组中元素个数错误.');
    elseif n~=n1+1
        error('MATLAB:Crout:不是三对角矩阵，参数数组中元素个数错误.');
    end
   
    %初始化
    L=zeros(n);%生成n*n的全零矩阵
    U=zeros(n);
    u=1:n;
    v=1:n-1;
    x=1:n;
    y=1:n;
   
    %追赶法程序主体
    u(1)=a(1);
    for i=1:n-1
        v(i)=b(i)/u(i);
        u(i+1)=a(i+1)-c(i)*v(i);
    end
    %正解y
    y(1)=e(1)/u(1);%用x存储y
    for i=2:n
        y(i)=(e(i)-c(i-1)*y(i-1))/u(i);
    end
    %倒解x
    x(n)=y(n);
    for i=(n-1):-1:1
        x(i)=y(i)-v(i)*x(i+1);
    end
    %L,U矩阵
    for i=1:n
        L(i,i)=u(i);
        U(i,i)=1;
    end
    for i=1:n-1
        L(i+1,i)=c(i);
        U(i,i+1)=v(i);
end %end of function
##### SOURCE END #####
-->
</body>
</html>